package com.chatbot.repository;

import com.chatbot.entity.CharacterMessage;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CharacterMessageRepository extends JpaRepository<CharacterMessage, Long> {
    // 根据对话ID查找所有消息
    List<CharacterMessage> findByCharacterConversation_CharacterConversationId(Long conversationId);
    
    // 根据对话ID分页查找消息
    Page<CharacterMessage> findByCharacterConversation_CharacterConversationId(Long conversationId, Pageable pageable);
    
    // 根据对话ID按时间戳降序查找消息
    List<CharacterMessage> findByCharacterConversation_CharacterConversationIdOrderByTimestampDesc(Long conversationId);
    
    // 根据对话ID按时间戳正序查找消息
    List<CharacterMessage> findByCharacterConversation_CharacterConversationIdOrderByTimestamp(Long conversationId);
    
    // 根据对话ID删除所有消息
    void deleteByCharacterConversation_CharacterConversationId(Long conversationId);
    
    // 根据对话ID和发送者类型查找消息
    List<CharacterMessage> findByCharacterConversation_CharacterConversationIdAndSenderType(Long conversationId, String senderType);
} 